# -*- coding: utf-8 -*- 
#
# Description:
#
#  Definiton
#
#
#
# Changes:
#
# 2012-01-10
# Initial Commit
#
#
# Copyright 2010-2012, WyDev Team.
# Author: Polo35 (polo35580@hotmail.fr)
#
# Licenced under Academic Free License version 3.0
# Review WyGui README & LICENSE files for further details.

nname: 0
n 0(None)[self.wdb = wdb
self.signalNewRecord = self.wdb.signal(config.wyrecord_dbus_path_name, 'signal_new_record', '(siiss)', interface=config.wyrecord_dbus_bus_name)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e7aec>}
nname: 75
n 75(None)[title = record_info.name
uri = record_info.url
self.signalNewRecord((channel_name, scheduled_start_time, scheduled_end_time, title, uri))
]:
	i: 0(t), 52()
	o: 

nname: 52
n 52(None)[]:
	i: 0(f)
	o: 75()

nname: 0
n 0(record_info.name)[channel_name = record_info.service_name
scheduled_start_time = record_info.start_time
scheduled_end_time = record_info.stop_time
duration = record_info.stop_time - record_info.start_time
]:
	i: 
	o: 52(f), 75(t)

nname: 0
n 0(None)[channel_name = record_info.service_name
scheduled_start_time = record_info.start_time
scheduled_end_time = record_info.stop_time
duration = record_info.stop_time - record_info.start_time
if not record_info.name:
	pass
title = record_info.name
uri = record_info.url
self.signalNewRecord((channel_name, scheduled_start_time, scheduled_end_time, title, uri))
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e7e2c>}
nname: 6
n 6(None)[def __init__(self, wdb):
	self.wdb = wdb
	self.signalNewRecord = self.wdb.signal(config.wyrecord_dbus_path_name, 'signal_new_record', '(siiss)', interface=config.wyrecord_dbus_bus_name)

def emitNewRecordInfo(self, record_info):
	channel_name = record_info.service_name
	scheduled_start_time = record_info.start_time
	scheduled_end_time = record_info.stop_time
	duration = record_info.stop_time - record_info.start_time
	if not record_info.name:
		pass
	title = record_info.name
	uri = record_info.url
	self.signalNewRecord((channel_name, scheduled_start_time, scheduled_end_time, title, uri))

]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb76e746c>}
nname: 233
n 233(None)[]:
	i: 122(), 213(), 232(AE)
	o: 

nname: 213
n 213(None)[log.error('failed to initialyse wycrs')
]:
	i: 0(except)
	o: 233()

nname: 122
n 122(None)[self.wdb_inst_standby = PowerManagerModule('wyrecord')
self.wdb_inst_standby.apm_ready = self.ext_standby.treat_StateReadySignal
self.wdb_inst_standby.apm_standby = self.ext_standby.treat_StateStandbySignal
self.wdb_inst_standby.apm_suspend = self.ext_standby.treat_StateSuspendSignal
self.wdb_inst_standby.apm_off = self.ext_standby.treat_StateOffSignal
]:
	i: 0(try)
	o: 233()

nname: 0
n 0(None)[self.wdb = wdb
self.scheduler = scheduler
self.ext_standby = ext_standby
self.live_manager = live_manager
self.wyscan = wyscan
self.wyscan.macrovision.register(self.dbus_handler_macrovision_signal)
self.wdb_inst_wyclock = self.wdb.instance(config.wyclock_dbus_path_name)
self.wdb_inst_wyclock.signal('TimeChanged', 'x', self.time_updated, WDB_AS_THREAD)
]:
	i: 
	o: 122(try), 213(except)

nname: 213
n 213(None)[except:
	log.error('failed to initialyse wycrs')
]:
	i: 0()
	o: 

nname: 0
n 0(None)[self.wdb = wdb
self.scheduler = scheduler
self.ext_standby = ext_standby
self.live_manager = live_manager
self.wyscan = wyscan
self.wyscan.macrovision.register(self.dbus_handler_macrovision_signal)
self.wdb_inst_wyclock = self.wdb.instance(config.wyclock_dbus_path_name)
self.wdb_inst_wyclock.signal('TimeChanged', 'x', self.time_updated, WDB_AS_THREAD)
try:
	self.wdb_inst_standby = PowerManagerModule('wyrecord')
	self.wdb_inst_standby.apm_ready = self.ext_standby.treat_StateReadySignal
	self.wdb_inst_standby.apm_standby = self.ext_standby.treat_StateStandbySignal
	self.wdb_inst_standby.apm_suspend = self.ext_standby.treat_StateSuspendSignal
	self.wdb_inst_standby.apm_off = self.ext_standby.treat_StateOffSignal
]:
	i: 
	o: 213()

nname: 0
n 0(None)[self.wdb = wdb
self.scheduler = scheduler
self.ext_standby = ext_standby
self.live_manager = live_manager
self.wyscan = wyscan
self.wyscan.macrovision.register(self.dbus_handler_macrovision_signal)
self.wdb_inst_wyclock = self.wdb.instance(config.wyclock_dbus_path_name)
self.wdb_inst_wyclock.signal('TimeChanged', 'x', self.time_updated, WDB_AS_THREAD)
try:
	self.wdb_inst_standby = PowerManagerModule('wyrecord')
	self.wdb_inst_standby.apm_ready = self.ext_standby.treat_StateReadySignal
	self.wdb_inst_standby.apm_standby = self.ext_standby.treat_StateStandbySignal
	self.wdb_inst_standby.apm_suspend = self.ext_standby.treat_StateSuspendSignal
	self.wdb_inst_standby.apm_off = self.ext_standby.treat_StateOffSignal
except:
	log.error('failed to initialyse wycrs')
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76ed98c>}
nname: 0
n 0(None)[log.debug('time_updated ' + str(delta_time))
self.live_manager.AsynchronousUpdateLiveTime(delta_time)
self.scheduler.AsynchronousCheckSchedule()
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e7e4c>}
nname: 64
n 64(None)[]:
	i: 3(), 44(), 63(AE)
	o: 

nname: 44
n 44(None)[log.debug('Change State => unknown state')
]:
	i: 0(except)
	o: 64()

nname: 3
n 3(None)[log.debug('Change State => state_to_call: ' + str(state))
self.state_to_call[state]()
]:
	i: 0(try)
	o: 64()

nname: 0
n 0(None)[]:
	i: 
	o: 3(try), 44(except)

nname: 44
n 44(None)[except:
	log.debug('Change State => unknown state')
]:
	i: 0()
	o: 

nname: 0
n 0(None)[try:
	log.debug('Change State => state_to_call: ' + str(state))
	self.state_to_call[state]()
]:
	i: 
	o: 44()

nname: 0
n 0(None)[try:
	log.debug('Change State => state_to_call: ' + str(state))
	self.state_to_call[state]()
except:
	log.debug('Change State => unknown state')
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76ed3ec>}
nname: 42
n 42(None)[]:
	i: 9(), 41()
	o: 

nname: 41
n 41(None)[]:
	i: 0(f)
	o: 42()

nname: 9
n 9(None)[WyrecordOnShotTimer(self.cbTreatMacrovisionSignal, service_id, has_macrovision).start(0)
]:
	i: 0(t)
	o: 42()

nname: 0
n 0(config.manage_macrovision)[]:
	i: 
	o: 9(t), 41(f)

nname: 0
n 0(None)[if config.manage_macrovision:
	WyrecordOnShotTimer(self.cbTreatMacrovisionSignal, service_id, has_macrovision).start(0)
]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76e7dac>}
nname: 6
n 6(None)[def __init__(self, wdb, scheduler, ext_standby, live_manager, wyscan):
	self.wdb = wdb
	self.scheduler = scheduler
	self.ext_standby = ext_standby
	self.live_manager = live_manager
	self.wyscan = wyscan
	self.wyscan.macrovision.register(self.dbus_handler_macrovision_signal)
	self.wdb_inst_wyclock = self.wdb.instance(config.wyclock_dbus_path_name)
	self.wdb_inst_wyclock.signal('TimeChanged', 'x', self.time_updated, WDB_AS_THREAD)
	try:
		self.wdb_inst_standby = PowerManagerModule('wyrecord')
		self.wdb_inst_standby.apm_ready = self.ext_standby.treat_StateReadySignal
		self.wdb_inst_standby.apm_standby = self.ext_standby.treat_StateStandbySignal
		self.wdb_inst_standby.apm_suspend = self.ext_standby.treat_StateSuspendSignal
		self.wdb_inst_standby.apm_off = self.ext_standby.treat_StateOffSignal
	except:
		log.error('failed to initialyse wycrs')

def time_updated(self, delta_time):
	log.debug('time_updated ' + str(delta_time))
	self.live_manager.AsynchronousUpdateLiveTime(delta_time)
	self.scheduler.AsynchronousCheckSchedule()

def ChangeState(self, state):
	try:
		log.debug('Change State => state_to_call: ' + str(state))
		self.state_to_call[state]()
	except:
		log.debug('Change State => unknown state')

def dbus_handler_macrovision_signal(self, service_id, has_macrovision):
	if config.manage_macrovision:
		WyrecordOnShotTimer(self.cbTreatMacrovisionSignal, service_id, has_macrovision).start(0)

cbTreatMacrovisionSignal = GlobalLock()()
]:
	i: 
	o: 

self.nodes: {6: <unpyclib.structure.node instance at 0xb76e7aec>}
nname: 0
n 0(None)[import time
from config import *
from logger import log
from wydbus import WDB_AS_THREAD
from peewee.powerutils import PowerManagerModule
from globallock import GlobalLock
from tools import WyrecordOnShotTimer
class DbusSignaler(object):
	def __init__(self, wdb):
		self.wdb = wdb
		self.signalNewRecord = self.wdb.signal(config.wyrecord_dbus_path_name, 'signal_new_record', '(siiss)', interface=config.wyrecord_dbus_bus_name)

	def emitNewRecordInfo(self, record_info):
		channel_name = record_info.service_name
		scheduled_start_time = record_info.start_time
		scheduled_end_time = record_info.stop_time
		duration = record_info.stop_time - record_info.start_time
		if not record_info.name:
			pass
		title = record_info.name
		uri = record_info.url
		self.signalNewRecord((channel_name, scheduled_start_time, scheduled_end_time, title, uri))



class DbusListener(object):
	def __init__(self, wdb, scheduler, ext_standby, live_manager, wyscan):
		self.wdb = wdb
		self.scheduler = scheduler
		self.ext_standby = ext_standby
		self.live_manager = live_manager
		self.wyscan = wyscan
		self.wyscan.macrovision.register(self.dbus_handler_macrovision_signal)
		self.wdb_inst_wyclock = self.wdb.instance(config.wyclock_dbus_path_name)
		self.wdb_inst_wyclock.signal('TimeChanged', 'x', self.time_updated, WDB_AS_THREAD)
		try:
			self.wdb_inst_standby = PowerManagerModule('wyrecord')
			self.wdb_inst_standby.apm_ready = self.ext_standby.treat_StateReadySignal
			self.wdb_inst_standby.apm_standby = self.ext_standby.treat_StateStandbySignal
			self.wdb_inst_standby.apm_suspend = self.ext_standby.treat_StateSuspendSignal
			self.wdb_inst_standby.apm_off = self.ext_standby.treat_StateOffSignal
		except:
			log.error('failed to initialyse wycrs')

	def time_updated(self, delta_time):
		log.debug('time_updated ' + str(delta_time))
		self.live_manager.AsynchronousUpdateLiveTime(delta_time)
		self.scheduler.AsynchronousCheckSchedule()

	def ChangeState(self, state):
		try:
			log.debug('Change State => state_to_call: ' + str(state))
			self.state_to_call[state]()
		except:
			log.debug('Change State => unknown state')

	def dbus_handler_macrovision_signal(self, service_id, has_macrovision):
		if config.manage_macrovision:
			WyrecordOnShotTimer(self.cbTreatMacrovisionSignal, service_id, has_macrovision).start(0)

	cbTreatMacrovisionSignal = GlobalLock()()


]:
	i: 
	o: 

self.nodes: {0: <unpyclib.structure.node instance at 0xb76df6cc>}
import time
from config import *
from logger import log
from wydbus import WDB_AS_THREAD
from peewee.powerutils import PowerManagerModule
from globallock import GlobalLock
from tools import WyrecordOnShotTimer
class DbusSignaler(object):
	def __init__(self, wdb):
		self.wdb = wdb
		self.signalNewRecord = self.wdb.signal(config.wyrecord_dbus_path_name, 'signal_new_record', '(siiss)', interface=config.wyrecord_dbus_bus_name)

	def emitNewRecordInfo(self, record_info):
		channel_name = record_info.service_name
		scheduled_start_time = record_info.start_time
		scheduled_end_time = record_info.stop_time
		duration = record_info.stop_time - record_info.start_time
		if not record_info.name:
			pass
		title = record_info.name
		uri = record_info.url
		self.signalNewRecord((channel_name, scheduled_start_time, scheduled_end_time, title, uri))



class DbusListener(object):
	def __init__(self, wdb, scheduler, ext_standby, live_manager, wyscan):
		self.wdb = wdb
		self.scheduler = scheduler
		self.ext_standby = ext_standby
		self.live_manager = live_manager
		self.wyscan = wyscan
		self.wyscan.macrovision.register(self.dbus_handler_macrovision_signal)
		self.wdb_inst_wyclock = self.wdb.instance(config.wyclock_dbus_path_name)
		self.wdb_inst_wyclock.signal('TimeChanged', 'x', self.time_updated, WDB_AS_THREAD)
		try:
			self.wdb_inst_standby = PowerManagerModule('wyrecord')
			self.wdb_inst_standby.apm_ready = self.ext_standby.treat_StateReadySignal
			self.wdb_inst_standby.apm_standby = self.ext_standby.treat_StateStandbySignal
			self.wdb_inst_standby.apm_suspend = self.ext_standby.treat_StateSuspendSignal
			self.wdb_inst_standby.apm_off = self.ext_standby.treat_StateOffSignal
		except:
			log.error('failed to initialyse wycrs')

	def time_updated(self, delta_time):
		log.debug('time_updated ' + str(delta_time))
		self.live_manager.AsynchronousUpdateLiveTime(delta_time)
		self.scheduler.AsynchronousCheckSchedule()

	def ChangeState(self, state):
		try:
			log.debug('Change State => state_to_call: ' + str(state))
			self.state_to_call[state]()
		except:
			log.debug('Change State => unknown state')

	def dbus_handler_macrovision_signal(self, service_id, has_macrovision):
		if config.manage_macrovision:
			WyrecordOnShotTimer(self.cbTreatMacrovisionSignal, service_id, has_macrovision).start(0)

	cbTreatMacrovisionSignal = GlobalLock()()


